package com.hkts.naturalgas.utils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @ClassNameTestDataUtils
 * @Description
 * @Author yck
 * @Date2020-09-17 14:40
 * @Version V1.0
 **/
public class TestDataUtils {
    //获取一段时间所有日期
    public static List<String> getDaysByTime(String[] dateArray) {
        List<String> list = new ArrayList<>();
        String[] dateBegs = dateArray[0].split("-");
        String[] dateEnds = dateArray[1].split("-");
        Calendar start = Calendar.getInstance();
        start.set(Integer.valueOf(dateBegs[0]), Integer.valueOf(dateBegs[1]) - 1, Integer.valueOf(dateBegs[2]));
        Long startTIme = start.getTimeInMillis();
        Calendar end = Calendar.getInstance();
        end.set(Integer.valueOf(dateEnds[0]), Integer.valueOf(dateEnds[1]) - 1, Integer.valueOf(dateEnds[2]));
        Long endTime = end.getTimeInMillis();
        Long oneDay = 1000 * 60 * 60 * 24L;
        Long time = startTIme;
        while (time <= endTime) {
            Date d = new Date(time);
            DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            time += oneDay;
            list.add(df.format(d));
        }
        return list;
    }
    // 获取流量压力数据
    public static float getHoursData() {
        float value = 0;
        Random rand = new Random();
        for (int i = 0; i < 10; i++) {
            value = rand.nextInt(100) + 1;
        }
        return value;
    }
    //获取近7天或近30天
    public static List<String> getDateArray(int value) {
        SimpleDateFormat ss = new SimpleDateFormat("yyyy-MM-dd");
        List<String> list = new ArrayList<>();
        for (int i = 0; i < value; i++) {
            list.add(ss.format(getYesterday(value - i)));
        }
        return list;
    }
    //获取日期
    public static Date getYesterday(int i) {
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DATE, -i);
        Date d = cal.getTime();
        return d;
    }
    //获取昨天
    public static Date getYesterday() {
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DATE, -1);
        Date d = cal.getTime();
        return d;
    }
   //获取某一天的压力值
    public static float getDateData() {
        float value = 0;
        Random rand = new Random();
        for (int i = 0; i < 10; i++) {
            value = rand.nextInt(100) + 1;
        }
        return value * 24;
    }
    //获取一天24小时数组
    public static List<String> getListHours(String date) {
        List<String> list = new ArrayList();
        for (int i = 0; i < 24; i++) {
            list.add(date + " " + i + ":00");
        }
        return list;
    }

    //排序
    public static List<Map<String, Object>> sortLiet(List<Map<String, Object>> list) {
        Collections.sort(list, new Comparator<Map<String, Object>>() {
            @Override
            public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                Float totalGateValue = Float.parseFloat(o1.get("totalGateValue").toString());
                Float totalGateValue2 = Float.parseFloat(o2.get("totalGateValue").toString());
                return -totalGateValue.compareTo(totalGateValue2);
            }
        });

        return list;
    }

    //获取当前
    //获取今天时间
    public static List<String> getTodayHours() {
        List<String> list = new ArrayList<String>();
        SimpleDateFormat dd = new SimpleDateFormat("yyyy-MM-dd");
        Calendar c = Calendar.getInstance();
        int hour = c.get(Calendar.HOUR_OF_DAY);
        for (int i = 0; i <= hour; i++) {
            list.add(dd.format(new Date()) + " " + i + ":00");
        }
        return list;
    }

    //报警信息转换
    public static String getGardeName(String grade) {
        if (grade.equals("1")) {
            return "一般";
        } else if (grade.equals("2")) {
            return "危险";
        } else {
            return "高危";
        }
    }
    //温度值
    public static float getTemperatureData() {
        float value = 0;
        Random rand = new Random();
        for (int i = 0; i < 10; i++) {
            value = rand.nextInt(60) + 1;
        }
        return value ;
    }
    //累积值
    public static float getAccumulateData() {
        float value = 0;
        Random rand = new Random();
        for (int i = 0; i < 10; i++) {
            value = rand.nextInt(100000) + 100000;
        }
        return value ;
    }
    //瞬时值
    // 获取流量压力数据
    public static float getInstantaneousData() {
        float value = 0;
        Random rand = new Random();
        for (int i = 0; i < 10; i++) {
            value = rand.nextInt(20) +160;
        }
        return value;
    }
    public static List<Date> getTimeSegment(int year, int month, int day) {
        Calendar cal = Calendar.getInstance();
        cal.set(year, month - 1, day, 1, 12, 0);
        cal.set(Calendar.MILLISECOND, 0);
        long startTime = cal.getTimeInMillis();
        cal.set(year, month, 10, 17, 0, 0);
        long endTime = cal.getTimeInMillis();
        final int seg = 5 * 60 * 1000;//五分钟
        ArrayList<Date> result = new ArrayList<Date>((int) ((endTime - startTime) / seg + 1));
        for (long time = startTime; time <= endTime; time += seg) {
            result.add(new Date(time));
        }
        return result;
    }
}
